import QtQuick 2.6

Rectangle{
    id:tipBox
    width:350
    height: 40
    radius: 10
    color: "#ffffff"
    z:100
    opacity: 0

   property url iconUrl: "qrc:/images/success_icon.png"
   property int second: 1000 //单位为毫秒

    Image{
        id: tipIcon
        source: iconUrl
        anchors.left: parent.left
        anchors.leftMargin: 10
        anchors.verticalCenter: parent.verticalCenter
        width:25
        height: 25
        z:tipBox.z+1
    }

    DDText{
        id:tipText
        anchors.left: tipIcon.right
        anchors.leftMargin: 4
        anchors.verticalCenter: parent.verticalCenter
        color: "#666666"
        text: "NeetPrint必印自动下载器Bate版"
        font.pixelSize:12
         z:tipBox.z+1
    }
    MouseArea{
        anchors.fill: parent
        onPressed:{
           mouse.accepted = true
        }
    }
    ShadowRectangle{
         anchors.centerIn: parent
         width: parent.width-5
         height: parent.height-5

         z:-1
     }
    Timer{
        id:hideTimer
        interval: tipBox.second
        repeat: false
        running: false //是否开启定时，默认是false，当为true的时候，进入此界面就开始定时
        triggeredOnStart: false // 是否开启定时就触发onTriggered，一些特殊用户可以用来设置初始值。
        onTriggered: {
            hideTip.start();
        }
    }
    ParallelAnimation{
        id:showTip

        YAnimator {
            id: animator
            target: tipBox
            from: tipBox.y
            to: tipBox.y+20

       }

        PropertyAnimation {
               id:animFadeIn
               target: tipBox
               duration: 200
               easing.type:  Easing.OutBounce
               property: 'opacity';
               from: 0;
               to: 1
        }
        onStopped: {
            hideTimer.start();
        }
    }
  ParallelAnimation{
        id:hideTip

        YAnimator {
            id: hideAnimator
            target: tipBox
            from: tipBox.y
            to: -10

       }

        PropertyAnimation {
               id:animHideFadeIn
               target: tipBox
               duration: 200
               easing.type:  Easing.InBounce
               property: 'opacity';
               from: 1;
               to: 0
        }

        onStopped: {
            tipBox.y=-10;
            tipBox.opacity=0;
            tipBox.visible=false;
        }
  }
   function show(status,texts){
       hideTimer.stop();
       tipBox.y=-10;
       tipBox.opacity=0;
       tipBox.visible=true;
       tipText.text=texts;
       if(status === "success"){
           tipIcon.source=iconUrl
       }
       if(status === "error"){
           tipIcon.source="qrc:/images/error_icon.png"
       }
       showTip.start();
    }
}
